package es.deusto.ingenieria.aike.formulation;

public class parkingState {

	private Cell[][] maze;
	private int[] carPosition = new int[2];
	private String carOrientation;
	private int flagRow;
	private int flagCol;

	/**
	 * Constructor method.  A problem state is instantiated with the given information.
	 * 
	 * @param information
	 *            Object having the information that describes a problem state.
	 */
	public parkingState(Cell[][] pMaze, int pCarPositionRow, int pCarPositionCol, String pCarOrientation, int fRow, int fCol) {
		maze=pMaze;
		carPosition[0]=pCarPositionRow;
		carPosition[1]=pCarPositionCol;
		carOrientation=pCarOrientation;
		flagRow=fRow;
		flagCol=fCol;
	}
	
	public Cell getCell(int row, int col){
	    return maze[row][col];
	}
	
	public int getCarPosRow(){
		return carPosition[0];
	}
	
	public int getCarPosCol(){
		return carPosition[1];
	}
	
	public String getOrientation(){
		return carOrientation;
	}
	
	public Object Clone(){
		Cell[][] pMaze=new Cell[this.maze.length][this.maze[0].length];
		for (int i=0; i < this.maze.length;i++){
			for (int j=0; j < this.maze[0].length; j++){
				pMaze[i][j]=(Cell)this.maze[i][j].clone();
			}
		}
		
		int carPosR= new Integer(this.carPosition[0]);
		int carPosC= new Integer(this.carPosition[1]);
		int flagR= new Integer(this.flagRow);
		int flagC= new Integer(this.flagCol);
		
		String carOrien= new String(this.carOrientation);
		
		parkingState pState= new parkingState(pMaze, carPosR, carPosC, carOrien, flagR, flagC);
		return pState;
	}

	
	public void moveCar(int row, int col){
		carPosition[0]=row;
		carPosition[1]=col;
	}
	
	public void setOrientation(String orien){
		carOrientation=orien;
	}
	
	public int getFlagRow(){
		return flagRow;
	}
	
	public int getFlagCol(){
		return flagCol;
	}
	
     /*
	 * Checks whether two states are the same. Redefinition of method
	 * <i>equals()</i> from class Object.
	 * 
	 * @param obj
	 *            Object against which the state is compared.
	 * @return boolean
	 *         <li><b>true</b> - if both states are described by the same information.</li>
	 *         <li><b>false</b> - otherwise.</li>
	 */
	public boolean equals(Object obj) {
		parkingState aux = (parkingState)obj;
		if (this.carPosition[0]==aux.getCarPosRow()&&this.carPosition[1]==aux.getCarPosCol()&&carOrientation.equals(aux.getOrientation())){
			return true;
		}
		else return false;
	}
	
	public String toString(){
		return ("Car position: "+carPosition[0]+" "+carPosition[1]+"    and Orientation: "+carOrientation);
	}
}
